﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using PowerCreator.LMS.Common.Script;

public partial class Theme_3_EditTheme :PowerCreator.LMS.Web.Base.WebBasePage
{
    PowerCreator.LMS.Web.BBS.ManagerBBS opBBS = new PowerCreator.LMS.Web.BBS.ManagerBBS();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected string itype = "0";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = config.GetLanagerValueByKey("theme_BBS_AddTheme", PowerCreator.LMS.Language.LanagetItemType.Page);
        if (!IsPostBack)
        {
            ViewState["Type"] = "0";
            itype = Request.QueryString["Type"].ToString();
            ViewState["Type"] = itype;

            ViewState["ThemeID"] = "0";
            string themeid = Request.QueryString["ThemeID"].ToString();
            ViewState["ThemeID"] = themeid;
            //BinderRoundTheme();
            BinderPageData();
        }
    }
    protected override void InitPage()
    {
        Button1.Text = GetLanageValueByKey("btn_EditResourceInfo_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        lab_tishi.Text = GetLanageValueByKey("theme_BBS_TitleMsg", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }
    //private void BinderRoundTheme()
    //{ 
    //    //随机推荐
    //    string search = "ThemeIsVisible = 1";
    //    string orderList = "  newid() ";
    //    DataTable dt = opBBS.QueryTheme(search, orderList, PowerCreator.LMS.Web.Config.WebConfig.PageSize, 1);
    //    rpt_RoundTheme.DataSource = dt;
    //    rpt_RoundTheme.DataBind();
    //}
    private void BinderPageData()
    {
        PowerCreator.LMS.BBS.Entity.VOTheme voTheme = new PowerCreator.LMS.BBS.Entity.VOTheme();
        voTheme = opBBS.LoadTheme(int.Parse(ViewState["ThemeID"].ToString()));

        if (voTheme.ThemeID > 0)
        {
            //PowerCreator.LMS.BBS.Entity.VODomain voDomain = opBBS.LoadDomain(voTheme.ThemeDomainID);
            //lbl_DomainName.Text = voDomain.DomainName;
            txt_ThemeTitle.Text = voTheme.ThemeTitle;
            txt_Description.Text = voTheme.ThemeContent;
            txt_AccessoryName.Text = voTheme.AccessoryName;
            
            for (int i = 0; i < dpdlst_AccessoryType.Items.Count; i++)
			{
                if (voTheme.AccessoryType.ToString() == dpdlst_AccessoryType.Items[i].Value)
                {
                    dpdlst_AccessoryType.Items[i].Selected = true;
                    return;
                }
			}
            
            
        }
    }
    private bool CheckPageData()
    {
        if (string.IsNullOrEmpty(txt_ThemeTitle.Text.Trim()))
        {
            Script.Alert(Page, "update", "请输入标题!");
            return false;
        }
        if (txt_ThemeTitle.Text.Length > 30)
        {
            Script.Alert(Page, "msg", "输入的标题太长，请小于30个字符");
            return false;
        }
        return true;
    }

    protected void btn_save_Click(object sender, EventArgs e)
    {
        if (!CheckPageData()) return;
        PowerCreator.LMS.BBS.Entity.VOTheme voTheme = new PowerCreator.LMS.BBS.Entity.VOTheme();
        voTheme = opBBS.LoadTheme(int.Parse(ViewState["ThemeID"].ToString()));
       voTheme.AccessoryName= txt_AccessoryName.Text;
        if (voTheme.ThemeID > 0)
        {
            voTheme.ThemeTitle = txt_ThemeTitle.Text;
            voTheme.ThemeContent = txt_Description.Text;
            if (opBBS.UpdateTheme(voTheme))
            {
                string url = "Theme.aspx?Type=" + ViewState["Type"].ToString()+"&ThemeID=" + ViewState["ThemeID"].ToString();
                Script.RedirectURL(url);
            }
        }
    }
}
